package com.zh.chat.gui.tree;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.tree.DefaultMutableTreeNode;

import com.zh.chat.entity.Friend;
import com.zh.chat.util.FileOperationUtil;
import com.zh.chat.util.FileType;

public class IconTreeNode extends DefaultMutableTreeNode {
	private static final long serialVersionUID = -8044774991176225332L;
	protected Icon icon;
	protected Friend friend;
	protected String text;

	public IconTreeNode(Friend friend) {// 包装对象为User实例的结点的构造方法
		this(friend, false);
	}
	
	/**
	 * 好友节点构造方法
	 * @param friend
	 * @param allowsChildren
	 */
	public IconTreeNode(Friend friend, boolean allowsChildren) {// allowsChildren也就是准不准许有孩子节点
		super(friend, allowsChildren);
		this.friend = friend;
		this.text = friend.getNickname();
		String path = FileOperationUtil.getFilePath(FileType.SCULPTURE, friend.getSysId(), friend.getImage());
		this.icon = new ImageIcon(path);
	}
	
	/**
	 * 分组节点构造方法
	 * @param dividedName
	 */
	public IconTreeNode(String dividedName) {
		super(dividedName, true);
		this.text = dividedName;
	}

	public void setIcon(Icon icon) {
		this.icon = icon;
	}

	public Icon getIcon() {
		return icon;
	}

	public Friend getFriend() {
		return friend;
	}

	public void setFriend(Friend friend) {
		this.friend = friend;
	}

	public String getText() {
		return this.text;
	}
}